package com.qf.cx.simplenms.persist.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.qf.cx.simplenms.persist.dao.api.SwitchDao;
import com.qf.cx.simplenms.persist.entity.SwitchEntity;

@Component
@Aspect
public class SwitchAspect {

	@Autowired
	private SwitchDao switchDao;

	@Pointcut("execution(* com.qf.cx.simplenms.persist.service..add*(..))")
	public void add() {
	}

	@Pointcut("execution(* com.qf.cx.simplenms.persist.service..update*(..))")
	public void update() {
	}

	@Pointcut("execution(* com.qf.cx.simplenms.persist.service..delete*(..))")
	public void delete() {
	}

	@Pointcut("execution(* com.qf.cx.simplenms.persist.service..Switch*.*(..))")
	public void switch0() {
	}

	@After("(add() || update() || delete()) && !switch0()")
	public void after(JoinPoint joinPoint) {
		switchDao.addSwitch(new SwitchEntity());
	}

}